package com.zhangxiaofanfan.hotcode.second;

/**
 * <a href="https://leetcode.cn/problems/linked-list-cycle/description/?envType=study-plan-v2&envId=top-100-liked">环形链表</a>
 *
 * @author zhangxiaofanfan
 * @date 2024-05-28 20:53:46
 */
public class HotCode025 {
    public static void main(String[] args) {
        // 没有写出来
    }

    public boolean hasCycle(ListNode head) {
        if (head == null) {
            return false;
        }
        ListNode indexQuick = head, indexSlow = head;
        while (true) {
            indexSlow = indexSlow.next;
            indexQuick = indexQuick.next;
            if (indexQuick == null) {
                return false;
            }
            indexQuick = indexQuick.next;
            if (indexSlow == null || indexQuick == null) {
                return false;
            }
            if (indexSlow == indexQuick) {
                return true;
            }
        }
    }

    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }


}
